var https = require("https");
var fs = require("fs");
var url = require("url");

var imgUrl = "https://pic2.zhimg.com/e2e0447636da75835f711d1579b02f19_m.jpg";

https.get(imgUrl, function(res){
    var obj = url.parse(imgUrl);
    var imgName = obj.pathname.split("/").pop();

    var imgData = "";

    res.setEncoding("binary");

    res.on("data", function(chunk){
        imgData += chunk;
    });

    res.on("end", function(){
        fs.writeFile(imgName, imgData, "binary", function(err){
            if(err){
                console.log("download fail");
            }

            console.log("download success.");
        });
    })
});